package com.testfileupload.uploadimg.design.interpreter;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Client {
    public static void main(String[] args) throws IOException {
        String expString = getExpString();
        System.out.println("expString" + expString);
        //赋值
        HashMap<String, Integer> var = getValue(expString);
        System.out.println(var);
        Calculator calculator = new Calculator(expString);
        System.out.println(calculator.run(var));
    }

    private static HashMap<String, Integer> getValue(String expString) throws IOException {
        HashMap<String, Integer> var = new HashMap<>();
        //解析有几个参数要传递
        for (char ch : expString.toCharArray()) {
            if (!String.valueOf(ch).equals("+") && !String.valueOf(ch).equals("-")) {
                //重复参数问题
                if (!var.containsKey(String.valueOf(ch))) {
                    String in = new BufferedReader(new InputStreamReader(System.in)).readLine();
                    var.put(String.valueOf(ch), Integer.valueOf(in));
                }
            }
        }

        return var;
    }

    private static String getExpString() throws IOException {
        System.out.println("请输入表达式");
        return new BufferedReader((new InputStreamReader(System.in))).readLine();
    }
}
